// import { useUserStore } from '@/stores/user'
import { useUserStore } from '@/stores/user'
import { createRouter, createWebHashHistory } from 'vue-router'

const router = createRouter({
  history: createWebHashHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/login',
      component: () => import('@/views/Login/loginPage.vue'),
    },
    {
      path: '/',
      component: () => import('@/views/layout/LayoutContainer.vue'),
      redirect: '/room/manage',
      children: [
        {
          path: '/device/manage',
          component: () => import('@/views/device/DeviceManage.vue'),
        },
        {
          path: '/room/manage',
          component: () => import('@/views/room/roomManage.vue'),

        },
        {
          path:'/user/profile',
          component: () => import("@/views/user/userProfile.vue"),

        },
        {
          path:'/user/password',
          component: () => import("@/views/user/setPassword.vue"),
        }
      ],
    },
    {
      path:"/test",
      component:() => import('@/views/test/testPage.vue')
    }
  ],
})

// 登录访问拦截
router.beforeEach((to) => {
  const userStore = useUserStore()
  if (!userStore.token && to.path !== '/login') return '/login'
})

export default router
